

cc.Class({
    extends: cc.Component,

    properties: {
        barrackPrefab:{  //募兵
            default: null,
            type :cc.Prefab,
        },
        detailPrefab:{  //详情
            default: null,
            type :cc.Prefab,
        },
        upgradePrefab:{  //升级
            default: null,
            type :cc.Prefab,
        },
        trainPrefab:{  //训练
            default: null,
            type :cc.Prefab,
        },
        getMoneyPrefab: { //征税
            default:null,
            type: cc.Prefab
        },
        studyPrefab:{ //研究
            default:null,
            type: cc.Prefab
        },
        topshow : {  //显示层
            default:null,
            type:cc.Node,
        },
        
    },

    // LIFE-CYCLE CALLBACKS:
    citybuttonclick: function(event, customeventdata) {
        var tgnode = event.target;       
        var tgnodename = tgnode.name;
        var topshow = this.topshow;      

        if(topshow.childrenCount > 0) {     //点击到其他节点的时候清除另一个节点的按钮
            for(var i = topshow.childrenCount - 1; i >= 0; i--) {
                topshow.children[i].destroy();
            }
        }
        cc.log(1)
        var icoArry = [this.detailPrefab, this.barrackPrefab, this.upgradePrefab];
        cc.log(tgnodename)
        switch(tgnodename) {  //兵营1
            case "barracks_one":
                var icoArry = [this.detailPrefab, this.barrackPrefab, this.upgradePrefab]  //详情，募兵，升级
            case "barracks_two":
                var icoArry = [this.detailPrefab, this.barrackPrefab, this.upgradePrefab] //详情，募兵，升级
                break;
            case "trainning":
                var icoArry = [this.detailPrefab, this.trainPrefab, this.upgradePrefab] // 详情，训练，升级
                break;
            case "castle":
                var icoArry = [this.detailPrefab, this.getMoneyPrefab, this.upgradePrefab] // 详情，增税，升级
                break;
            case "school":
                var icoArry = [this.detailPrefab, this.studyPrefab, this.upgradePrefab] // 详情，学习，升级
                break;
            case "warehouse_one": //仓库
                var icoArry = [this.detailPrefab,this.upgradePrefab] // 详情，升级
                break;
            case "warehouse_two":
                var icoArry = [this.detailPrefab, this.upgradePrefab] // 详情,升级
                break;
            case "warehouse_four":
                var icoArry = [this.detailPrefab,  this.upgradePrefab] // 详情,升级
                break;
            case "house": //民居
                var icoArry = [this.detailPrefab,  this.upgradePrefab] // 详情,升级
                break;
            case "hood": //伐木场
                var icoArry = [this.detailPrefab,  this.upgradePrefab] // 详情,升级
                break;
            case "stone":  //石材厂
                var icoArry = [this.detailPrefab,  this.upgradePrefab] // 详情,升级
                break;
            case "farm":  //农田
                var icoArry = [this.detailPrefab,  this.upgradePrefab] // 详情,升级
                break;
            default:
                return;
        }
        cc.log(1)
        // 设置按钮位置，显示在被点击节点的下方
        var basePosition = tgnode.convertToWorldSpaceAR(cc.v2(0, 0));
        var localPosition = topshow.parent.convertToNodeSpaceAR(basePosition);
        if(icoArry[2]) {
            var node1 = cc.instantiate(icoArry[0])
            var node2 = cc.instantiate(icoArry[1])
            var node3 = cc.instantiate(icoArry[2])
            node2.x = localPosition.x+10 
            node2.y = localPosition.y-80
            node1.x = node2.x-70
            node1.y = node2.y+30
            node3.x = node2.x+70
            node3.y = node2.y+30

            topshow.addChild(node1)
            topshow.addChild(node2)
            topshow.addChild(node3)
        }else {
            var node1 = cc.instantiate(icoArry[0])
            var node2 = cc.instantiate(icoArry[1])
           
            node2.x = localPosition.x+30 
            node2.y = localPosition.y-80
            node1.x = node2.x-70
            node1.y = node2.y
            topshow.addChild(node1)
            topshow.addChild(node2)
        }
        
         
       
    },
    onLoad: function() {},

    start () {

    },

    // update (dt) {},
});
